package communication;

import lombok.Data;

@Data
public class Clerk implements Runnable {
    static final int MAX_PRODUCTION = 20;
    private int production = 0;

    public Clerk() {
    }

    public Clerk(int production) {
        this.production = production;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (this) {
                try {
                    wait(2000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                if (this.getProduction() < MAX_PRODUCTION) {
                    notify();
                }
            }
        }
    }
}
